package com.ccyl.repository.impl;

import com.ccyl.entity.Admin_user;
import com.ccyl.repository.AdminRepository;
import com.ccyl.util.JDBCTools;

import java.sql.*;

public class AdminRepositoryImpl implements AdminRepository {

    @Override
    public Admin_user login(String user, String password) {
        Connection connection = JDBCTools.getConnection();
        String sql = "SELECT * FROM users WHERE binary user = ? AND binary password = ?";
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        Admin_user admin_user = null;
        try {
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1,user);
            preparedStatement.setString(2,password);
            resultSet = preparedStatement.executeQuery();
            if (resultSet.next()) {
                admin_user=new Admin_user(resultSet.getString(1),resultSet.getString(2));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            JDBCTools.release(connection,preparedStatement,resultSet);
        }
        return admin_user;
    }
}
